package org.springframework.web.servlet.ajax.json;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.View;

/**
 * A View implementation that holds the content it renders rather than
 * committing that content to the HttpServletResponse.  
 * 
 * @author Charles Tassoni
 *
 */

public class HoldsContentView implements View {

	private View delegate;
	private StringBuffer content;

	public void setDelegate(View delegate) {
		this.delegate = delegate;
	}

	public String getContentType() {
		return delegate.getContentType();
	}

	public void render(Map model, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		StringBuffer buf = new StringBuffer();
		HttpServletResponse proxy = HttpServletResponseProxy.newInstance(response, buf);
		delegate.render(model, request, proxy);

		this.content = buf;
	}

	public StringBuffer getContent() {
		return content;
	}



}
